package TimeToWork.Android;

import android.content.Context;
import android.content.SharedPreferences;

public class SharedPrefsAdapter {
	public static final String PREFS_NAME = "TimeToWork";
	
	private static final String CHECK_IN_TIME = "CheckInTime";
	
	private SharedPreferences sharedPreferences;
	private SharedPreferences.Editor editor;
	
	public SharedPrefsAdapter(Context context) {
		this.sharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
	}
	
	private void openEditor() {
		this.editor = this.sharedPreferences.edit();
	}
	
	public boolean setCheckInTime(MyTime checkInTime) {
		this.openEditor();
		this.editor.putLong(CHECK_IN_TIME, checkInTime.getTimeInMillis());
	    return this.editor.commit();
	}
	
	public boolean deleteCheckInTime() {
		return this.setCheckInTime(new MyTime(0));
	}
	
	public MyTime getCheckInTime() {
		return new MyTime(this.sharedPreferences.getLong(CHECK_IN_TIME, 0));
	}
	
}
